import {
  getServerSideCategories,
  getServerSideProducts,
} from '@/services/back';
import { getCategoryByPaths, parseUrlToFetchParams } from '@/utils/common';
import CategoriesPage from '@/views/Categories';
import { notFound } from 'next/navigation';

export default async function Page(props: any) {
  console.log('=========== start app/Promotion/page ===========');
  const categories = await getServerSideCategories();
  const slug = props?.params?.slug;
  const paths = slug?.map((p: any) => p.replace(/\.html?$/i, '')) || [];
  const currCategory = getCategoryByPaths(paths, categories);
  if (paths?.length && !currCategory) {
    return notFound();
  }
  const pageTitle = 'Promotion';
  // const queryParams = parseUrlToFetchParams(
  //   'promotion',
  //   paths,
  //   props?.searchParams,
  //   categories
  // );
  // const skusInfo = await getServerSideProducts(queryParams);
  // console.log('💡 result skus >>', skusInfo?.result?.length);
  const skusInfo = null;
  return (
    <CategoriesPage
      {...props}
      paths={paths}
      pageTitle={pageTitle}
      category={currCategory}
      categories={categories || []}
      products={skusInfo || {}}
    />
  );
}
